package com.ym.controller.admin;

import com.ym.core.annotation.Log;
import com.ym.core.domain.APIResponse;
import com.ym.core.domain.BaseController;
import com.ym.medical.service.ISortTableSV;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;

/**
 * 给表的排序字段排序
 *
 * @author: 李涛
 * @version: 2019年07月17日 16:51
 */
@Api(tags = "admin-给列表排序")
@RestController
@RequestMapping("/common/sort")
@Validated
public class SortTableController extends BaseController {

	@Autowired
	private ISortTableSV sortTableSV;

	@Log
	@ApiOperation("排序")
	@ApiImplicitParams({
			@ApiImplicitParam(value = "拖拽标志(nav_doctor_infor,nav_popu_dept_infor,nav_quick_entry_infor)", name = "tableName", paramType = "form"),
			@ApiImplicitParam(value = "上", name = "top", paramType = "form"),
			@ApiImplicitParam(value = "中", name = "mid", paramType = "form"),
			@ApiImplicitParam(value = "下", name = "bottom", paramType = "form"),
			@ApiImplicitParam(value = "条件", name = "whereCase", paramType = "form"),
	})
	@PostMapping("/sortTable")
	public APIResponse sortTable(
			@NotNull String tableName,
			Long top,
			@NotNull Long mid,
			Long bottom,
			String[] whereCase
	) {
		boolean sortSuccess = sortTableSV.sortTable(tableName, top, mid, bottom, whereCase);
		if (!sortSuccess) {
			return success();
		}
		return successMsg("排序成功!");
	}

}
